package zzz.EasyMock.Demo02_模擬HttpServletRequest;

import java.io.UnsupportedEncodingException;
import java.net.URLDecoder;
import java.util.HashMap;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;

import org.easymock.EasyMock;
import org.junit.Assert;
import org.junit.Test;

/**
 * 演示Record-Replay-Verify模型，这个模型首先记录mock对象上的操作然后重演并验证这些操作。
 */


public class Demo02 {
    public static void main(String[] args) throws UnsupportedEncodingException {
        HttpServletRequest request = EasyMock.createMock(HttpServletRequest.class);
        EasyMock.expect(request.getParameter("ffff")).andReturn("ffff=33333");
        EasyMock.expect(request.getParameter("ffff")).andReturn("ffff=444");
        EasyMock.expect(request.getRealPath("/")).andReturn("/=fffffffff").anyTimes();
        
        EasyMock.replay(request);
        System.out.println(request.getRealPath("/"));
        System.out.println(request.getParameter("ffff"));
        System.out.println(request.getRealPath("/"));
        System.out.println(request.getParameter("ffff"));
        
        // 回收
        EasyMock.verify(request);
    }    
}
